using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ComputeCluster;

namespace UACluster.UAClusterAdmin
{
    public class ClusterBase
    {

        ICluster bCluster = null;
        ITask bTask = null;
        //IJob bJob = null;
        string bName = "localhost";
        string bLogin = null;
        string bPassword = null;

        public ClusterBase(string clusterName, string clusterLogin, string clusterPassword)
        {
            setClusterName(clusterName);
            setClusterLogin(clusterLogin);
            setClusterPassword(clusterPassword);
        }

        public ClusterBase()
        {
        }

        public ICluster initCluster()
        {
            ICluster c = new Cluster();
            c.Connect(bName);
            return c;
        }

        public ITask initTask()
        {
            ITask t = new Task();
            return t;
        }

        public ITask initTask(string CommandLine, string NodesList)
        {
            ITask t = new Task();
            t.RequiredNodes = NodesList;
            t.CommandLine = CommandLine;
            return t;
        }

        public void ExecuteCommand(string CommandLine, string NodesList)
        {
            bCluster = initCluster();
            bTask = initTask();
            bTask.CommandLine = CommandLine;
            bTask.RequiredNodes = NodesList;
            //bCluster.Timeout = 1000;
            bCluster.IsAsynchronous = true;
            bCluster.ExecuteCommand(bCluster.GetNewCommandId(), bTask, bLogin, bPassword, false, 0);
            //bCluster.ExecuteCommand(bTask.Id, bTask, bLogin, bPassword, true, 0);

            return;
        }

        public void getRunningTasks(string NodesList)
        {
            bCluster = initCluster();
        }
 
        public void setClusterName(string ClusterName)
        {
            bName = ClusterName;
        }

        public string getClusterName()
        {
            return bName;
        }

        public void setClusterLogin(string newLogin)
        {
            bLogin = newLogin;
        }

        public void setClusterPassword(string newPassword)
        {
            bPassword = newPassword;
        }

        public string getClusterLogin()
        {
            return bLogin;
        }

        public string getClusterPassword()
        {
            return bPassword;
        }
    }

}
